#include "MatrixScreen.h"

// 构造函数
MatrixScreen::MatrixScreen (uint8_t sdaPin, uint8_t sclPin) : Matrix (sdaPin, sclPin) {}

// 初始化
void MatrixScreen::initScreen  () {
    // 写入地址
    this->begin(0x70);
    // 设置屏幕方向
    this->setRotation(2);
    // 清屏
    this->clear();
    this->write();
}

// 画点
void MatrixScreen::drawPoint (int x, int y, int operation) {
    this->drawPixel(x, 7-y, operation);
    this->write();
}

// 画直线
void MatrixScreen::drawMatrixLine (int x0, int y0, int x1, int y1, int operation) {
    this->drawLine(x0, 7-y0, x1, 7-y1, operation);
    this->write();
}

// 屏幕全亮或全灭
void MatrixScreen::drawScreen (int operation) {
    this->fillScreen(operation);
    this->write();
}

// 显示文字
void MatrixScreen::displayText (String text) {
    this->setCursor(0, 0);
    this->print(text);
    this->write();
}

// 滚动显示文字
void MatrixScreen::displayScrollText (String text, int delayTime) {
    this->scrollMessage(text, delayTime);
}

// 显示图案
void MatrixScreen::displayImage (const uint8_t * matrix_image) {
    for (int i = 0; i < 8; ++ i) {
        uint8_t pixel = matrix_image[i];
        for (int j = 0; j < 8; ++ j) {
            if ((pixel & 0x01) > 0)
                this->drawPixel(7 - j, 7 - i, 1);
            else
                this->drawPixel(7 - j, 7 - i, 0);
            pixel = pixel >> 1;
        }
    }
    this->write();
}

// 屏幕方向
void MatrixScreen::setScreenRotation (int angle) {
    switch (angle) {
        case 0: this->setRotation(2); break;
        case 1: this->setRotation(3); break;
        case 2: this->setRotation(1); break;
        case 3: this->setRotation(0); break;
    }
}

// 设置屏幕亮度
void MatrixScreen::setScreenBrightness (int brightness) {
    this->setBrightness(brightness);
}

// 清屏
void MatrixScreen::clearScreen () {
    this->clear();
    this->write();
}